<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>组件化</title>
  <script src="vue.js"></script>
</head>

<body>
  <div id="app">
    <input type="text" v-model="todoVal">
    <button @click="btnClick">提交</button>
    <ul>
      <todo-item v-bind:content="item" v-for="item in List"></todo-item>
    </ul>
  </div>

  <script>
    // 使用组件 改造TodoList
    // 将填充列表提取成组件
    // Vue.component 创建全局组件方法
    // Vue.component('TodoItem', {
    //   props: ['content'],
    //   template:"<li>{{content}}</li>"
    // })

    // 创建局部组件
    var TodoItem = {
      props: ['content'],
      template:"<li>{{content}}</li>"
    }
    var app = new Vue({
      el: '#app',
      components: {
        TodoItem
      },
      data: {
        todoVal: '',
        List: []
      },
      methods: {
        btnClick: function() {
          this.List.push(this.todoVal);
          this.todoVal = ''
        }
      }
    });

  </script>

</body>

</html>